#include <thread>
#include <fstream>
#include <iostream>
#include "logger/logger.hpp"
#include "clocker/clocker.h"
#include "./smart/smart_camera.hpp"

int main(const int argc, const char* argv[])
{
    int frame_num = 30;
    SmartCamera cam;
    cam.init("/dev/video0", 5, 1920, 1080, V4L2_PIX_FMT_UYVY);
    std::ofstream file("tst_camera_1920x1080_uyvy.yuv", std::ios::out | std::ios::binary); // 打开文件用于读取

    getchar();

    cam.loop_recv_frame([&cam, &frame_num, &file](uint8_t *buf, uint32_t len){
        clocker_end();
        file.write((char*)buf, 1920*1080*2);
        log_debug("---------------------------------> frame len[%d] num[%d]", len, --frame_num);
        clocker_begin();
        if (frame_num <= 0) {
            cam.stop();
        }
    });
    file.close();
    return 0;
}